<template>
	<!-- 学生 预习已完成统计页面 -->
	<page-body>
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center examinationRes_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub examinationRes_fd0_0'>
					<view class='flex flex-wrap align-center examinationRes_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  examinationRes_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='examinationRes_fd0_0_c1_c0'>结果统计</text>
					</view>
					<view class='flex flex-wrap align-center justify-end examinationRes_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout examinationRes_flex_1">
				<view class="zt" v-if="graded == 0">
					待教师批阅
				</view>
				<view class='flex flex-wrap align-center examinationRes_fd1_0'>
					<view class=" examinationRes_fd1_0_c0">
						<qiun-data-charts v-if="shows" :canvas2d='true' :reshow='true' :chartData="chartsOptsfd1_0_c0"
							:ontouch='true' chart-type='6' type='ring' :opts='chartsOptsfd1_0_c0' />
					</view>
					<view class='flex flex-wrap align-center justify-between examinationRes_fd1_0_c1'>
						<view
							class='flex flex-direction flex-wrap align-center self-center justify-around examinationRes_fd1_0_c1_c0'>
							<text class='examinationRes_fd1_0_c1_c0_c1'>{{$t('得分')}}</text>
							<view class='flex flex-wrap align-center'>
								<text class='examinationRes_fd1_0_c1_c0_c0_c0'>{{dataList.score}}</text>
								<!-- <text class='examinationRes_fd1_0_c1_c0_c0_c1'>{{$t('分')}}</text> -->
							</view>
							
						</view>
						<view
							class='flex flex-direction flex-wrap align-center self-center justify-around examinationRes_fd1_0_c1_c0'>
							<text class='examinationRes_fd1_0_c1_c0_c1'>未计分题数</text>
							<view class='flex flex-wrap align-center'>
								<text class='examinationRes_fd1_0_c1_c0_c0_c0'>{{dataList.not_jifen}}</text>
								<!-- <text class='examinationRes_fd1_0_c1_c0_c0_c1'>%</text> -->
							</view>
							
						</view>
						<view @click="toranking" class='flex flex-direction flex-wrap align-center self-center justify-around examinationRes_fd1_0_c1_c0'>
							<text class='examinationRes_fd1_0_c1_c0_c1'>当前排名</text>
							<view class='flex flex-wrap align-center'>
								<text class='examinationRes_fd1_0_c1_c0_c0_c0'>{{dataList.rank}}</text>
								<!-- <text class='examinationRes_fd1_0_c1_c0_c0_c1'>%</text> -->
							</view>
							
						</view>
					</view>
					<!-- <view class="pm" @click="toranking">
						当前排名：8
					</view> -->
				</view>
				<view class='   examinationRes_fd1_1'>
					<image class="fx" :src='STATIC_URL+"1669.png"' mode=""></image>
					<view v-if="percent!==100" class='flex flex-wrap align-center examinationRes_fd1_1_c0'>
						
						<!-- <text class='examinationRes_fd1_1_c0_c0'>{{$t('AI分析：')}}</text> -->
						<view class='flex flex-direction  align-center justify-center examinationRes_fd1_1_c0_c1'>
							
							<image style="width: 300rpx;height: 300rpx;" :src='STATIC_URL+"AI.gif"' mode=""></image>
							<view class='flex flex-wrap align-center'>
								<text class='examinationRes_fd1_1_c0_c1_c2_c0'>{{$t('AI分析中…')}}</text>
							</view>
							<!-- <view class='flex flex-wrap align-center'>
								<view class='flex benben-progress-bar examinationRes_fd1_1_c0_c1_c1_c0'>
									<view class='benben-progress-bar-center examinationRes_progress1_fd1_1_c0_c1_c1_c0'
										:style="{width: percent+'%'}"></view>
							
								</view>
							</view> -->
							<view class='flex flex-wrap align-center'>
								<text class='examinationRes_fd1_1_c0_c1_c0_c0'>{{percent}}</text>
								<text class='examinationRes_fd1_1_c0_c1_c0_c1'>%</text>
							</view>
						</view>
						<jyf-parser class='examinationRes_fd1_1_c0_c2'>
						</jyf-parser>
					</view>

					<view v-else class='flex flex-wrap align-center MyPortrayal_fd1_7_c1_c1'>
						
						<text class='MyPortrayal_fd1_7_c1_c1_c0' v-html="textStr"></text>
					</view>
				</view>
			</view>
			<!---flex布局flex布局结束-->
			<!--  v-if="cwnum>0 && graded==1" -->
			<view class="flex benben-position-layout flex flex-wrap align-center examinationRes_flex_2"
				@click="goBackHandle"
				:style="{paddingBottom:bottomSafeAreaRpx+'rpx', }">
				<!-- <view class=" btns " @tap.stop="jumpdetail()">
					查看错题
				</view> -->
				<view class=" btns " @tap.stop="jumpdetail()">
					查看详情
				</view>
				<view class=" btns" v-if="dataList.comment" @tap.stop="jumppy()">
					查看教师评语
				</view>
			</view>
			<!-- <view class="flex benben-position-layout flex flex-wrap align-center examinationRes_flex_2"  v-if="cwnum>0 && graded==1"
				@click="goBackHandle"
				:style="{paddingBottom:bottomSafeAreaRpx+'rpx', }">
				<view class="btn" @tap.stop="jumpdetail()" v-if="cwnum>0">
					查看错题
				</view>
				<view class=" btns " @tap.stop="jumpdetail()"  v-if="cwnum>0">
					查看详情
				</view>
				<view class="btn" @tap.stop="jumppy()" v-if="graded == 1">
					查看教师评语
				</view>
			</view> -->
			<view :style="{height: (110+bottomSafeAreaRpx)+'rpx'}"></view>
		</view>
	</page-body>
</template>
<script>
	import {
		mdToHtml
	} from '@/common/utils/mdParser.js'
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},
		data() {
			return {
				shows: false,
				percent: 0,
				textStr: '',
				"chartsOptsfd1_0_c0": {
					"padding": [5, 5, 5, 5],
					// "series": [{
					//   "name":"正确",
					//   data:1
					//   }, {
					//     "name":"错误",
					//     data:1
					//   }, {
					//     "name":"未做",
					//     data:1
					//   }],
					"dataLabel": false,
					"enableScroll": false,
					"legend": {
						"show": true,
						"position": "right",
						"lineHeight": 30,
						"fontSize": 15
					},
					"title": {
						"name": "正确",
						"fontSize": 15,
						"color": "#666666"
					},
					"subtitle": {
						"name": "3",
						"fontSize": 20,
						"color": "#333333"
					},
					"extra": {
						"ring": {
							"ringWidth": 20,
							"activeOpacity": 0.5,
							"activeRadius": 10,
							"offsetAngle": 0,
							"labelWidth": 15,
							"border": false,
							"borderWidth": 3,
							"borderColor": "#FFFFFF"
						}
					}
				},
				"dataList": [],
				type:0,//2课前预习  3课后作业
				aid:'',//作业记录id
				cwnum:'',//错误数量
				graded:'',//批阅状态
				homework_id:'',
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			let {
				aid
			} = options
			if (aid !== undefined) this.aid = aid
			this.type=options.type
			this.graded=options.graded
			this.homework_id=options.homework_id
			this.get66f37a7c752efFunc()
			// if(this.type==2){
			// 	this.aid=options.aid
			// 	this.getjd6f37a7c752efFunc()
			// }else if(this.type==3){
			// 	this.get66f37a7c752efFunc()
			// }
			
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			let that = this;
			var s = setInterval(item => {
				if (that.percent <= 99) {
					that.percent++
				} else {
					clearInterval(s)
				}
			}, 150)
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//APP接口-学生预习作业批改结果统计
			async getjd6f37a7c752efFunc() {
				// return
				//请求方法
				//数据验证

				let datadataList = await this.$api.get(global.apiUrls.post68d0be47e32b6, {
					user_id: uni.getStorageSync('USER_INFO').aid,
					homeworkreleaserecord_id:this.aid,
				});

				if (datadataList.data.code != 1) {
					this.$message.info(datadataList.data.msg);
					return
				}
				let infodataList = datadataList.data;
				this.dataList = infodataList.data
				let arr = []
				arr = this.dataList.chart_data
				// console.log("infodataList=>",infodataList.data.chart_data)
				// if()
				arr.forEach(item => {
					item.data = item.value
					
					delete item.value
				})

				this.chartsOptsfd1_0_c0.series = arr
				console.log("this.chartsOptsfd1_0_c0.series=>", arr)
				this.chartsOptsfd1_0_c0.subtitle.name = arr[2].data
				this.shows = true
				this.$forceUpdate()
				
				//ai分析
				this.comprehensiveAnalysis(this.dataList.chart_data)
			},

			
			//APP接口-学生作业批改结果统计
			async get66f37a7c752efFunc() {
				//请求方法
				//数据验证
			
				let datadataList = await this.$api.post(global.apiUrls.post68d4de1d23ee5, {
					// user_id: uni.getStorageSync('USER_INFO').aid,
					homeworkreleaserecord_id:this.aid,
				});
			
				if (datadataList.data.code != 1) {
					this.$message.info(datadataList.data.msg);
					return
				}
				let infodataList = datadataList.data;
				this.dataList = infodataList.data
				let arr = []
				arr = this.dataList.chart_data
				console.log("infodataList=>",infodataList.data.chart_data)
				// if()
				// arr=[{value:2, name:"未答"},{value:0, name:"错误"},{value:1, name:"正确"},{value:4, name:"未计分"}]
				arr.forEach(item => {
					item.data = item.value
					if(item.name=='错误'){
						this.cwnum=item.value
					}
					if(item.name=='正确'){
						item.color='#4AD57A'
					}else if(item.name=='错误'){
						item.color='#FFAF5F'
					}else {
						item.color='#7686FC'
					}
					item.name=item.name+' '+item.value
					
					delete item.value
				})
				console.log(arr)
				this.chartsOptsfd1_0_c0.series = arr
				console.log("this.chartsOptsfd1_0_c0.series=>", arr)
				this.chartsOptsfd1_0_c0.subtitle.name = arr[2].data
				this.shows = true
				this.$forceUpdate()
				console.log(this.cwnum)
				//ai分析
				this.comprehensiveAnalysis(this.dataList.chart_data)
			},
			
			toranking(){
				uni.navigateTo({
					url:'/pages/kc/ranking/ranking?aid='+this.aid
				})
			},
			
			
			//AI分析
			async comprehensiveAnalysis(arr) {
				const str = JSON.stringify(arr)
				//ai分析
				let res2 = await this.$api.post(global.apiUrls.post68c910fcdbef9, {
					agent_id:'62',
					query: `【${str}】，根据数据给出该学生作业测试的详细分析及学习建议`
				})

				if (res2.data.code != 1) {
					this.$message.info(res2.data.msg);
					return
				} else {
					this.textStr =  mdToHtml(res2.data.data.answer)
					// this.textStr =  res2.data.data.answer
				}
			},
			jumpdetail(){
				let isgraded=this.graded==1?'true':"false"
				uni.redirectTo({
					url:'/pages/kc/xtdetail/xtdetail?homeworkreleaserecord_id='+this.aid+'&uid='+uni.getStorageSync('USER_INFO').aid+'&homework_id='+this.homework_id+'&isgraded='+isgraded
				})
				return
				uni.redirectTo({
					url:'/pages/kc/errotm/errotm?id='+this.aid
				})
			},
			jumppy(){
				uni.navigateTo({
					url:'/pages/kc/teacherjspy/teacherjspy?title='+this.dataList.comment+'&type=0'
				})
			},
			goBackHandle() {
				uni.navigateBack(1)
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page{
		background: url(image-path('1666.png')) no-repeat;
		background-size: 100% auto;
	}
	.MyPortrayal_fd1_7_c1_c1 {
		// background: #f3f6f8;
		border-radius: 16rpx;
		background-size: 100% auto;
		padding: 24rpx;
		height: 700rpx;
		overflow-y: auto;
	}

	.MyPortrayal_fd1_7_c1_c0_c2_c0 {
		font-size: 24rpx;
		color: #333;
		font-weight: 500;
		line-height: 33rpx;
	}

	.page {
		width: 100vw;
		min-height: 100vh;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		// background: #F8F8F8;
		// background-size: 100% auto;
		
	}

	.examinationRes_flex_0 {
		// background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
		color: #fff;
	}

	.examinationRes_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 700;
		// color: #333333;
		line-height: 50rpx;
	}

	.examinationRes_fd0_0_c0_c0 {
		font-size: 36rpx;
		// color: #333;
	}

	.examinationRes_fd0_0_c0 {
		width: 120rpx;
	}

	.examinationRes_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.examinationRes_flex_1 {
		padding: 24rpx;
	}

	::v-deep .examinationRes_fd1_1_c0_c2 {
		width: 100%;
	}

	.examinationRes_fd1_1_c0_c1_c2_c0 {
		color: #145EFD;
		font-size: 24rpx;
		font-weight: 500;
	}

	.examinationRes_progress1_fd1_1_c0_c1_c1_c0 {
		background: #145EFD;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	.examinationRes_fd1_1_c0_c1_c1_c0 {
		border: 1px solid rgba(20, 94, 253, 0.1);
		background: rgba(20, 94, 253, 0.10);
		width: 300rpx;
		height: 20rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 24rpx 0rpx 24rpx 0rpx;
		background-size: 100% auto;
	}

	.examinationRes_fd1_1_c0_c1_c0_c1 {
		font-size: 32rpx;
		color: rgba(20, 94, 253, 1);
	}

	.examinationRes_fd1_1_c0_c1_c0_c0 {
		font-size: 48rpx;
		color: rgba(20, 94, 253, 1);
		font-weight: 700;
		line-height: 60rpx;
	}

	.examinationRes_fd1_1_c0_c1 {
		width: 100%;
		min-height: 300rpx;
	}

	.examinationRes_fd1_1_c0_c0 {
		width: 100%;
		margin: 0rpx 0rpx 24rpx 0rpx;
		color: rgba(20, 94, 253, 1);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 48rpx;
	}
	.fx{
		width: 118rpx;
		height: 47rpx;
		
	}

	.examinationRes_fd1_1_c0 {
		// background: #f3f6f8;
		width: 100%;
		padding: 24rpx;
		background-size: 100% auto;
		border-radius: 16rpx;
	}

	.examinationRes_fd1_1 {
		background: var(--benbenbgColor1);
		margin: 0rpx 0rpx 24rpx 0rpx;
		padding: 24rpx;
		background-size: 100% auto;
		border-radius: 32rpx;
		min-height: 630rpx;
	}

	.examinationRes_fd1_0_c1_c0_c1 {
		color: rgba(102, 102, 102, 1);
		line-height: 48rpx;
	}

	.examinationRes_fd1_0_c1_c0_c0_c1 {
		color: #333;
		font-size: 28rpx;
		font-weight: 700;
	}

	.examinationRes_fd1_0_c1_c0_c0_c0 {
		color: #145EFD;
		font-size: 40rpx;
		font-weight: 700;
		font-style: inherit;
	}

	.examinationRes_fd1_0_c1_c0 {
		// background: #F3F6F8;
		height: 100%;
		width: 33%;
		// background-size: 100% auto;
		// border-radius: 16rpx;
	}

	.examinationRes_fd1_0_c1 {
		// margin: 24rpx 0rpx 0rpx 0rpx;
		width: 100%;
		height: 160rpx;
	}
	.pm{
		margin-top: 32rpx;
		width: 100%;
		height: 128rpx;
		background: #F3F6F8;
		text-align: center;
		line-height: 128rpx;
	}

	.examinationRes_fd1_0_c0 {
		width: 100%;
		height: 360rpx;
	}

	.examinationRes_fd1_0 {
		background: url(image-path('1668.png')) no-repeat;
		background-size: 100% auto;
		margin: 0rpx 0rpx 24rpx 0rpx;
		padding: 24rpx;
		background-size: 100% auto;
		border-radius: 32rpx;
		width: 702rpx;
		height: 563rpx;
	}
	.zt{
		width: 702rpx;
		height: 84rpx;
		background: #FAE4C4;
		border-radius: 16rpx;
		line-height: 84rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #FF7812;
		text-align: center;
		font-style: normal;
		text-transform: none;
		margin-bottom: 24rpx;
	}
	.examinationRes_flex_2 {
		width: 100%;
		height: 110rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}
	.btn{
		width: 702rpx;
		height: 84rpx;
		background: url(image-path('1667.png')) no-repeat;
		background-size: 100% auto;
		margin-left: 24rpx;
		text-align: center;
		line-height: 84rpx;
		color: #fff;
	}
	.btns{
		margin-left: 24rpx;
		text-align: center;
		line-height: 84rpx;
		color: #fff;
		width: 48%;
		margin: 0 auto;
		height: 84rpx;
		border-radius: 16rpx;
		// background: linear-gradient( 289deg, #24FFFF 0%,#437AFD 50%, #28B4FC 100%) !important;
		background: linear-gradient(to right,
		    #24FFFF 0%, 
		    #437AFD 50%, 
		    #A66FFF 100%
		);
	
	}

	.examinationRes_fd2_0 {
		background: #4781f5;
		width: 100%;
		line-height: 110rpx;
		font-size: 32rpx;
		color: #fff;
		border-radius: 0rpx;
	}
</style>
